package cn.tedu.v1.controller;


import cn.tedu.v1.model.DepartmentOffice;
import cn.tedu.v1.service.IDepartmentOfficeService;
import cn.tedu.v1.vo.AppointmentVo;
import cn.tedu.v1.vo.ChartVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 部门列表 前端控制器
 * </p>
 *
 * @author tedu.cn
 * @since 2021-07-06
 */
@RestController
@RequestMapping("/portal/departmentOffice")
@Slf4j
public class DepartmentOfficeController {
    @Autowired
    private IDepartmentOfficeService departmentOfficeService;

    private ChartVo chartVo = new ChartVo();

    @GetMapping("/dol")
    public List<DepartmentOffice> departmentOffices() {
        List<DepartmentOffice> departmentOffices = departmentOfficeService.getDepartmentOffice();
        return departmentOffices;
    }

    @GetMapping("/medicaldepartment")
    public List<DepartmentOffice> medicalDepartment() {
        List<DepartmentOffice> medicalDepartment = departmentOfficeService.medicalDepartment();
        return medicalDepartment;
    }

    @GetMapping("delete")
    public String deleteDepartmentOffice(Integer Id){
        int num=departmentOfficeService.deleteDepartmentOffice(Id);
        if(num==1)
            return "删除成功";
        return "服务器忙!";
    }

    @GetMapping("/chart")
    public ChartVo Chart(){
        chartVo = departmentOfficeService.getDepartmentCount();
        chartVo = departmentOfficeService.getDepartmentName();
        chartVo = departmentOfficeService.getDepartmentColor();
        return chartVo;
    }

    @PostMapping("/add_department")
    public String addDepartment(@Validated DepartmentOffice departmentOffice){
        log.debug("添加部门内容:{}",departmentOffice);
        int num = departmentOfficeService.addDepartment(departmentOffice);
        if(num == 0){
            return "服务器忙";
        }else {
            return "添加成功";
        }
    }
}
